package com.example.demo.tc;

import com.alibaba.excel.EasyExcel;
import com.example.demo.model.CargoData;
import com.example.demo.utils.BigDecimalCollector;
import com.example.demo.utils.BigDecimalUtils;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author linjingze
 * @date 2024/4/22 17:09
 */
public class Test {

    public static void main(String[] args) {
        String cpFile = "/Users/linjingze/Downloads/文瑶3月帐单(1).xls";
        String wyFile = "/Users/linjingze/Downloads/文鳐系统应付账单2024-04-22 16-37-13.xlsx";

        List<FeeInfo> cpList = EasyExcel.read(cpFile).head(FeeInfo.class).sheet().doReadSync();
        List<FeeInfo> wyList = EasyExcel.read(wyFile).head(FeeInfo.class).sheet().doReadSync();
        Map<String, BigDecimal> wyMap = wyList.stream().filter(f -> {
            boolean b = f.getBlNo() != null;
            if (!b) {
                System.out.println("WY提单号为空的序号="+f.getSeq());
            }
            return b;
        }).collect(Collectors.groupingBy(FeeInfo::getBlNo, Collectors.mapping(FeeInfo::getPrice, BigDecimalCollector.toSum())));
        Map<String, BigDecimal> cpMap = cpList.stream().filter(f -> {
            boolean b = f.getBlNo() != null;
            if (!b) {
                System.out.println("CP提单号为空的序号="+f.getSeq());
            }
            return b;
        }).collect(Collectors.groupingBy(FeeInfo::getBlNo, Collectors.mapping(FeeInfo::getAmount, BigDecimalCollector.toSum())));

        //for (int i = 1; i <= cpList.size(); i++) {
        //    FeeInfo feeInfo = cpList.get(i);
        //
        //}
        for (Map.Entry<String, BigDecimal> e : cpMap.entrySet()) {
            String key = e.getKey();
            BigDecimal wyBigDecimal = wyMap.get(key);
            if (wyBigDecimal == null) {
                System.out.println("提单号="+key+"在文鳐不存在");
                continue;
            }
            if (!BigDecimalUtils.equals(wyBigDecimal, e.getValue())) {
                System.out.println("提单号="+key+",文鳐金额="+wyBigDecimal+",CP金额="+e.getValue());
            }
        }
    }

}
